#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#define N 2

int main()
{
	int status, i;
	pid_t pid;

	for (i = 0; i < N; ++i)
	{
		if((pid = fork()) == 0)
			exit(100+i);
	}

	while((pid = waitpid(-1, &status, 0)) > 0) {
		if(WIFEXITED(status))
			printf("normally %d, %d\n", pid, WEXITSTATUS(status));
		else
			printf("abnormally %d\n", pid);
	}

	if(errno != ECHILD)
	{
		fprintf(stderr, "%s: %s\n", "waitpid error", strerror(errno));
	}

	exit(0);
}
